"""
新增日志页面
"""
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from tools.tools import Tada

class LogNewPage(BasePage):
    url = '/crm/index.php?m=log&a=mylog_add'
    commerce_locator = (By.ID, 'business_name')
    commerce_btn_locator = (By.CSS_SELECTOR, '#data > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)')
    commerce_btn_last_locator = (By.XPATH, '//*[@id="data"]/tr[3]/td[1]/input[1]')
    commerce_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')
    log_title_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[2]/input')
    log_content_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(8) > td:nth-child(2) > div > div.ke-edit > iframe')
    log_add_btn_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')
    type_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[3]/td[2]/input[1]')
    type_last_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[3]/td[2]/input[4]')
    del_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    del_btn_locator = (By.ID,'delete')

    #清除标题
    def clear_title(self):
        self.driver.find_element(*self.log_title_locator).clear()

    #输入标题
    def input_title(self,title):
        self.driver.find_element(*self.log_title_locator).send_keys(title)

    #点击商机
    def click_commerce(self):
        self.driver.find_element(*self.commerce_locator).click()

    #商机选择第一个
    def commerce_one(self,tr):
        t = Tada(self.driver)
        t.taba_find(tr)


    #商机选择最后一个
    def commerce_last(self,tr,td=0):
        t = Tada(self.driver)
        t.taba_find(tr)


    #商机保存
    def commerce_btn(self):
        self.driver.find_element(*self.commerce_ok_locator).click()

    #输入内容
    def input_content(self,content):
        self.driver.find_element(*self.log_content_locator).send_keys(content)

    #日志类型第一个
    def type_one(self):
        self.driver.find_element(*self.type_locator).click()

    #日志类型最后一个
    def type_last(self):
        self.driver.find_element(*self.type_last_locator).click()

    #保存日志
    def log_btn(self):
        self.driver.find_element(*self.log_add_btn_locator).click()

    #选择要清理的日志
    def del_log(self):
        self.driver.find_element(*self.del_locator).click()

    #删除按键
    def del_btn(self):
        self.driver.find_element(*self.del_btn_locator).click()